import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import type { FC } from 'react';
import type { LessonItem, LessonListParams } from '../data.d';
import { getLessonList } from '../service';

interface LessonTableProps {
  actionRef: React.RefObject<ActionType>;
  columns: ProColumns<LessonItem>[];
}

const LessonTable: FC<LessonTableProps> = ({ actionRef, columns }) => {
  return (
    <ProTable<LessonItem, LessonListParams>
      headerTitle="Lesson 列表"
      actionRef={actionRef}
      rowKey="LessonID"
      search={{
        labelWidth: 120,
      }}
      request={async (params, sorter, filter) => {
        const result = await getLessonList({
          ...params,
          ...sorter,
          ...filter,
        });
        return {
          data: result.data || [],
          success: result.success || false,
          total: result.total || 0,
        };
      }}
      columns={columns}
      pagination={{
        defaultPageSize: 10,
        showSizeChanger: true,
        showQuickJumper: true,
      }}
    />
  );
};

export default LessonTable;

